/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.rational.sheet.table.column;

import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.JTable;
import javax.swing.table.JTableHeader;

/**
 *
 * @author Overmind
 */
public class ColumnHeaderMouseAddapter
    extends MouseAdapter 
{
    public ColumnHeaderMouseAddapter()
    {
	
    }
    
    @Override
    public void mouseClicked(MouseEvent me)
    {
	super.mouseClicked(me);

	if(me.getSource() instanceof JTableHeader)
	{
	    JTableHeader header = (JTableHeader)me.getSource();
	    JTable table = header.getTable();
	    
	    int index = table.convertColumnIndexToModel(
		table.columnAtPoint(me.getPoint()));

	    if(index >= 0)
	    {
		table.setColumnSelectionInterval(index, index);
		table.setRowSelectionInterval(0, table.getRowCount() - 1);
	    }
	}
	else
	{
	    throw new ClassCastException("Source most be instanceof JTable");
	}
    }
}
